package com.blomholm.dev.todo;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.os.Bundle;
import android.view.*;
import android.view.View.OnKeyListener;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;

public class TodoList extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        final EditText txtNewItem = (EditText)findViewById(R.id.txtNewItem);
        ListView listTodo = (ListView)findViewById(R.id.listTodo);
        
        final ArrayList<String> todoItems = new ArrayList<String>();
        
        final ArrayAdapter<String> aa = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, todoItems);
        
        listTodo.setAdapter(aa);
        
        txtNewItem.setOnKeyListener(new OnKeyListener() {
        	public boolean onKey(View v, int keyCode, KeyEvent event) {
            	if(event.getAction() == KeyEvent.ACTION_DOWN) {
            		if(keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
            			todoItems.add(0, txtNewItem.getText().toString());
            			aa.notifyDataSetChanged();
            			txtNewItem.setText("");
            			return true;
            		}
            	}
            	return false;
            }
        });
    }
    
    
}